package org.autocode.util;

/**
 * @program: autocode
 * @description:
 * @author: zhu.xiaojie
 * @create: 2020-08-22 01:28
 */
public class JavaUtils {

    public static String toJavaClassName(String name){
        name = toJavaFieldName(name);
        String start = String.valueOf(name.charAt(0)).toUpperCase();
        String end = name.substring(1);
        return start + end;
    }

    public static String toJavaFieldName(String name){
        if(name == null){
            return null;
        }
        String low = String.valueOf(name.charAt(0)).toLowerCase();
        String under = name.substring(1);
        name = low + under;
        if(!name.contains("_")){
            return name;
        }
        if(name.charAt(0) == '_'){
            name = name.substring(1);
        }
        int ind = -1;
        while ((ind = name.indexOf("_")) != -1){
            String start = name.substring(0 , ind);
            String end = name.substring(ind + 1);
            String endFirst = String.valueOf(end.charAt(0)).toUpperCase();
            String endEnd = "";
            if(end.length() > 1){
                endEnd = end.substring(1);
            }
            end = endFirst + endEnd;
            name = start + end;
        }



        return name;
    }
}
